package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysNbaPlayer;
import com.ruoyi.system.service.ISysNbaPlayerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 球员信息Controller
 * 
 * @author yqg
 * @date 2023-11-02
 */
@Controller
@RequestMapping("/system/player")
public class SysNbaPlayerController extends BaseController
{
    private String prefix = "system/player";

    @Autowired
    private ISysNbaPlayerService sysNbaPlayerService;

    @RequiresPermissions("system:player:view")
    @GetMapping()
    public String player()
    {
        return prefix + "/player";
    }

    /**
     * 查询球员信息列表
     */
    @RequiresPermissions("system:player:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysNbaPlayer sysNbaPlayer)
    {
        startPage();
        List<SysNbaPlayer> list = sysNbaPlayerService.selectSysNbaPlayerList(sysNbaPlayer);
        return getDataTable(list);
    }

    /**
     * 导出球员信息列表
     */
    @RequiresPermissions("system:player:export")
    @Log(title = "球员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysNbaPlayer sysNbaPlayer)
    {
        List<SysNbaPlayer> list = sysNbaPlayerService.selectSysNbaPlayerList(sysNbaPlayer);
        ExcelUtil<SysNbaPlayer> util = new ExcelUtil<SysNbaPlayer>(SysNbaPlayer.class);
        return util.exportExcel(list, "球员信息数据");
    }

    /**
     * 新增球员信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存球员信息
     */
    @RequiresPermissions("system:player:add")
    @Log(title = "球员信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysNbaPlayer sysNbaPlayer)
    {
        return toAjax(sysNbaPlayerService.insertSysNbaPlayer(sysNbaPlayer));
    }

    /**
     * 修改球员信息
     */
    @GetMapping("/edit/{playerId}")
    public String edit(@PathVariable("playerId") Integer playerId, ModelMap mmap)
    {
        SysNbaPlayer sysNbaPlayer = sysNbaPlayerService.selectSysNbaPlayerByPlayerId(playerId);
        mmap.put("sysNbaPlayer", sysNbaPlayer);
        return prefix + "/edit";
    }

    /**
     * 修改保存球员信息
     */
    @RequiresPermissions("system:player:edit")
    @Log(title = "球员信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysNbaPlayer sysNbaPlayer)
    {
        return toAjax(sysNbaPlayerService.updateSysNbaPlayer(sysNbaPlayer));
    }

    /**
     * 删除球员信息
     */
    @RequiresPermissions("system:player:remove")
    @Log(title = "球员信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysNbaPlayerService.deleteSysNbaPlayerByPlayerIds(ids));
    }
}
